<page-header [title]="'商品管理'">
  添加、删除、修改商品，上下架、库存、规格、退换货规则等操作。
</page-header>

<nz-card [nzBordered]="false">
  <form
    nz-form
    [nzLayout]="'inline'"
    (ngSubmit)="getData()"
    class="search__form"
  >
    <nz-row [nzGutter]="{ md: 8, lg: 24, xl: 48 }">
      <nz-col nzMd="8" nzSm="24">
        <nz-form-item>
          <nz-form-label nzFor="no">规则编号</nz-form-label>
          <nz-form-control>
            <input
              nz-input
              [(ngModel)]="q.no"
              name="no"
              placeholder="请输入"
              id="no"
            />
          </nz-form-control>
        </nz-form-item>
      </nz-col>
      <nz-col nzMd="8" nzSm="24">
        <nz-form-item>
          <nz-form-label nzFor="status">使用状态</nz-form-label>
          <nz-form-control>
            <nz-select
              [(ngModel)]="q.status"
              name="status"
              id="status"
              [nzPlaceHolder]="'请选择'"
              [nzShowSearch]="true"
            >
              <nz-option
                *ngFor="let i of status; let idx = index"
                [nzLabel]="i.text"
                [nzValue]="idx"
              ></nz-option>
            </nz-select>
          </nz-form-control>
        </nz-form-item>
      </nz-col>
      <nz-col nzMd="8" nzSm="24" *ngIf="expandForm">
        <nz-form-item>
          <nz-form-label nzFor="callNo">调用次数</nz-form-label>
          <nz-form-control> <input nz-input id="callNo" /> </nz-form-control>
        </nz-form-item>
      </nz-col>
      <nz-col nzMd="8" nzSm="24" *ngIf="expandForm">
        <nz-form-item>
          <nz-form-label nzFor="updatedAt">更新日期</nz-form-label>
          <nz-form-control> </nz-form-control>
        </nz-form-item>
      </nz-col>
      <nz-col nzMd="8" nzSm="24" *ngIf="expandForm">
        <nz-form-item>
          <nz-form-label nzFor="status2">使用状态</nz-form-label>
          <nz-form-control>
            <nz-select
              [nzPlaceHolder]="'请选择'"
              nzId="status2"
              [nzShowSearch]="true"
            >
              <nz-option
                *ngFor="let i of status; let idx = index"
                [nzLabel]="i.text"
                [nzValue]="idx"
              ></nz-option>
            </nz-select>
          </nz-form-control>
        </nz-form-item>
      </nz-col>
      <nz-col nzMd="8" nzSm="24" *ngIf="expandForm">
        <nz-form-item>
          <nz-form-label nzFor="status3">使用状态</nz-form-label>
          <nz-form-control>
            <nz-select
              [nzPlaceHolder]="'请选择'"
              nzId="status3"
              [nzShowSearch]="true"
            >
              <nz-option
                *ngFor="let i of status; let idx = index"
                [nzLabel]="i.text"
                [nzValue]="idx"
              ></nz-option>
            </nz-select>
          </nz-form-control>
        </nz-form-item>
      </nz-col>
      <nz-col [nzSpan]="expandForm ? 24 : 8" [class.text-right]="expandForm">
        <button
          nz-button
          type="submit"
          [nzType]="'primary'"
          [nzLoading]="loading"
        >
          查询
        </button>
        <button nz-button type="reset" (click)="reset()" class="mx-sm">
          重置
        </button>
        <a (click)="expandForm = !expandForm">
          {{ expandForm ? '收起' : '展开' }}
          <i
            class="anticon"
            [class.anticon-down]="!expandForm"
            [class.anticon-up]="expandForm"
          ></i>
        </a>
      </nz-col>
    </nz-row>
  </form>

  <button nz-button (click)="add(modalContent)" [nzType]="'primary'">
    <i nz-icon type="plus"></i> <span>新建</span>
  </button>
  
  <ng-container *ngIf="selectedRows.length > 0">
    <button nz-button>批量操作</button>
    <nz-dropdown [nzPlacement]="'bottomLeft'">
      <button nz-button nz-dropdown>
        更多操作 <i nz-icon type="down"></i>
      </button>
      <ul nz-menu>
        <li nz-menu-item (click)="remove()">删除</li>
        <li nz-menu-item (click)="approval()">批量审批</li>
      </ul>
    </nz-dropdown>
  </ng-container>
  <div class="my-md">
    <nz-alert [nzType]="'info'" [nzShowIcon]="true" [nzMessage]="message">
      <ng-template #message>
        已选择
        <strong class="text-primary">{{ selectedRows.length }}</strong> 项
        <a *ngIf="totalCallNo > 0" (click)="st.clearCheck()" class="ml-lg"
          >清空</a
        >
      </ng-template>
    </nz-alert>
  </div>
  <st
    #st
    [columns]="columns"
    class="img64px"
    [data]="data"
    [loading]="loading"
    (change)="stChange($event)"
  >
    <ng-template st-row="status" let-i>
      <nz-badge [nzStatus]="i.statusType" [nzText]="i.statusText"></nz-badge>
    </ng-template>
  </st>
</nz-card>

<!-- spu 弹窗 -->
<ng-template #modalContent>
  <nz-card [nzBordered]="false">
    <form nz-form [formGroup]="form" se-container="1" labelWidth="100">
      <se label="商品名称" error="" required>
        <input nz-input formControlName="spuName" placeholder="" />
      </se>
      <se label="商品主图" error="" required>
        <div class="clearfix">
          <nz-upload
            nzAction="https://xcx.ruiysoft.com/reserve/qiniu/upload"
            [nzCustomRequest]="customReq"
            nzListType="picture-card"
            [(nzFileList)]="fileList"
            [nzShowButton]="fileList.length < 9"
            [nzPreview]="handlePreview"
            [nzRemove]="onRemoveFile"
            [nzMultiple]="true"
          >
            <i nz-icon type="plus"></i>
            <div class="ant-upload-text">上传</div>
          </nz-upload>
          <nz-modal
            [nzVisible]="previewVisible"
            [nzContent]="modalContent"
            [nzFooter]="null"
            (nzOnCancel)="previewVisible = false"
          >
            <ng-template #modalContent>
              <img [src]="previewImage" [ngStyle]="{ width: '100%' }" />
            </ng-template>
          </nz-modal>
        </div>
      </se>
      <se label="商品分类" error="" required>
        <nz-select formControlName="categoryId" [nzShowSearch]="true">
          <nz-option
            *ngFor="let i of categoryList; let idx = index"
            [nzLabel]="i.name"
            [nzValue]="i.id"
          ></nz-option>
        </nz-select>
      </se>
      <se label="退换货规则" extra="">
        <nz-select formControlName="returnRuleId" [nzShowSearch]="true">
          <nz-option
            *ngFor="let i of returnRuleList; let idx = index"
            [nzLabel]="i.name"
            [nzValue]="i.id"
          ></nz-option>
        </nz-select>
      </se>
      <se label="规格" error="请输入目标描述" required (click)="showHideButton()">
        <button
          nz-button
          (click)="addSpecification(modalContent2)"
          [nzType]="'primary'"
        >
          <i nz-icon type="plus"></i> <span>新建</span>
        </button>
        
        <button nz-button (click)="showRuleValues(modalContent3)" [nzType]="'primary'" *ngIf="showHide">
          <span>规格列表</span>
        </button>
        <st
          #st
          [columns]="columns4Standard"
          class="img64px"
          [data]="skus"
          [loading]="loading"
          (change)="stChange($event)"
        >
          <ng-template
            st-row="listPrice"
            let-item
            let-index="index"
            let-column="column"
          >
            {{ (item.listPrice / 1).toFixed(2) }}
          </ng-template>

          <ng-template
            st-row="unitPrice"
            let-item
            let-index="index"
            let-column="column"
          >
            {{ (item.unitPrice / 1).toFixed(2) }}
          </ng-template>
        </st>
      </se>

      <se label="商品详情" required>
        <button nz-button nzType="default" (click)="openWindow()">
          微信html编辑器
        </button>
        <textarea
          nz-input
          formControlName="info"
          rows="4"
          placeholder="请输入商品详情"
        >
        </textarea>
      </se>

      
    </form>
  </nz-card>
</ng-template>

<ng-template #modalContent2>
  <nz-card [nzBordered]="false">
    <form nz-form [formGroup]="form2" se-container="1" labelWidth="150">
      <se label="规格分类" error="不能为空" required>
        <input nz-input formControlName="ruleName" placeholder="" />
      </se>
      <se label="规格值" error="不能为空" required>
        <input nz-input formControlName="value" placeholder="" />
      </se>
      <se label="规格分类2" error="不能为空">
        <input nz-input formControlName="ruleName2" placeholder="" />
      </se>
      <se label="规格值2" error="不能为空">
        <input nz-input formControlName="value2" placeholder="" />
      </se>
      <se label="规格分类3" error="不能为空">
        <input nz-input formControlName="ruleName3" placeholder="" />
      </se>
      <se label="规格值3" error="不能为空">
        <input nz-input formControlName="value3" placeholder="" />
      </se>
      <se label="图片" error="" required>
        <div class="clearfix">
          <nz-upload
            nzAction="https://xcx.ruiysoft.com/reserve/qiniu/upload"
            [nzCustomRequest]="customReq2"
            nzListType="picture-card"
            [(nzFileList)]="fileList2"
            [nzShowButton]="fileList2.length < 1"
            [nzPreview]="handlePreview"
            [nzRemove]="onRemoveFile2"
          >
            <i nz-icon type="plus"></i>
            <div class="ant-upload-text">上传</div>
          </nz-upload>
          <nz-modal
            [nzVisible]="previewVisible"
            [nzContent]="modalContent"
            [nzFooter]="null"
            (nzOnCancel)="previewVisible = false"
          >
            <ng-template #modalContent>
              <img [src]="previewImage" [ngStyle]="{ width: '100%' }" />
            </ng-template>
          </nz-modal>
        </div>
      </se>
      <se label="市场价格(元)" error="不能为空" required>
        <input nz-input formControlName="listPrice" placeholder="" />
      </se>
      <se label="销售价格(元)" error="不能为空" required>
        <input nz-input formControlName="unitPrice" placeholder="" />
      </se>
      <se label="支付组合" error="不能为空">
        <nz-radio-group formControlName="radioValue">
          <label nz-radio nzValue="1" checked>会员价、积分，二选一</label>
          <label nz-radio nzValue="2">固定会员价 + 固定积分</label>
          <label nz-radio nzValue="3">会员价、积分，任意组合</label>
        </nz-radio-group>
      </se>
      <se label="会员价(元)" error="不能为空">
        <input nz-input formControlName="memberPrice" placeholder="" />
      </se>
      <se label="兑换积分" error="不能为空">
        <input nz-input formControlName="integral" placeholder="" />
      </se>
      <se label="库存" error="不能为空" required>
        <input nz-input formControlName="quantity" placeholder="" />
      </se>
    </form>
  </nz-card>
</ng-template>

<ng-template #modalContent3>
  <nz-card [nzBordered]="false">
    <st
      #st
      [columns]="columns4RuleValues"
      [data]="_ruleValues"
      [loading]="loading"
      (change)="stChange($event)"
    >
    </st>
  </nz-card>
</ng-template>
